package thread;

public class ThreadInterruptDemo {
    public static void main(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread thread = new Thread() {
            int i = 0, j = 0;

            @Override
            public void run() {
                synchronized (obj) {
                    i ++;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    j ++;
                }
            }

            @Override
            public String toString() {
                return "{" +
                        "i=" + i +
                        ", j=" + j +
                        '}';
            }
        };
        thread.start();
        Thread.sleep(200);
//        thread.stop();
        synchronized (obj) {
            System.out.println("get monitor");
        }
        thread.interrupt();
        Thread.sleep(1000);
        System.out.println(thread);
    }
}
